#!/bin/bash

# set -e
set -u
ABF_CLIENT="${ABF_CLIENT:-$HOME/bin/abf-console-client/abf.py}"
dir0="$PWD"
mkdir -p gits
cd logs

for i in *
do
	if grep '^error: Bad source:' "$i"; then
		cd "${dir0}/gits"
		git clone git@abf.io:import/${i}.git -b rosa2019.1
		cd "$i"
		"${dir0}/spectool.pl" -g *.spec
		"$ABF_CLIENT" put
		if git commit -m "bot: fix sources (mass#2225)" .abf.yml ; then
			git push
			"$ABF_CLIENT" build --no-extra-tests -b rosa2019.1 -p import/${i}
		fi
		cd "${dir0}/logs"
	fi
done 
